<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/patrol/index.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/page.css">
  </script>

<div class="box-box">
    <div class="boxQuery">
        <ul class=" layui-row">
            <li class="layui-col-md4 layui-col-sm4">
                <div style="margin-right: 23px;">公司：<input type="text"></div>
                <div>工单名称：<input type="text"></div>
                <div>工单编号：<input type="text"></div>
            </li>
            <li class="layui-col-md4 layui-col-sm4">
                <div style="margin-right: 103px;"> 巡检计划：
                    <select>
                        <option value=""></option>
                        <option value="H">时</option>
                        <option value="D">日</option>
                        <option value="W">周</option>
                        <option value="M">月</option>
                    </select>
                </div>
                <div>巡检人：<input type="text"></div>
                <div style="margin-left: 10px;">巡检时间：<input type="text" id="time"></div>
            </li>
            <li class="layui-col-md4 layui-col-sm4">
                <div>位置范围：<input type="text"></div>
                <div>设备编号：<input type="text"></div>
                <div style="margin-right: 90px;">工单状态：
                    <!-- <input type="number"> -->
                    <select class="fil05">
                        <option value=""></option>
                        <option value="1">未开始</option>
                        <option value="2">待执行</option>
                        <option value="9">已完成</option>
                    </select>
                </div>
            </li>

        </ul>
        <div class="footer layui-btn-container" style="justify-content: center">

            <button class="sure layui-btn layui-btn-radius layui-btn-primary">
                确定
            </button>
            <button class="close layui-btn layui-btn-radius layui-btn-primary">
                关闭
            </button>
            <button class="reset layui-btn layui-btn-radius layui-btn-primary">
                清空
            </button>
        </div>
    </div>

    <div class="box layui-fluid layui-row">
        <div class="btn-box layui-btn-container layui-row" style="padding: 0 5px;">
            <button class="btn3 layui-btn layui-btn-radius layui-btn-primary" style="background: #ccdae3;">
                <i class="layui-icon layui-icon-add-circle" style="font-size: 14px; color: #1E9FFF;"></i>
                <span style="color: #666666;">创建工单</span>
            </button>
            <button class="btn2 layui-btn layui-btn-radius layui-btn-primary" style="margin-left: 20px;">
                <i class="layui-icon layui-icon-add-circle" style="font-size: 14px; color: #FFF;"></i>
                <span>转单</span>
            </button>
            <button style="width: 80px;background: orangered;"
                class="search layui-btn layui-btn-radius layui-btn-primary layui-col-sm6 layui-col-md6">
                <i class="layui-icon layui-icon-search" style="font-size: 10px; color: #FFF;"></i>
                <span>条件查询</span>
            </button>
        </div>

        <table id="maintainWork" lay-skin='nob' lay-filter="maintainWork" lay-even></table>
        <div class="footer layui-btn-container">
            <button class="btn1 layui-btn layui-btn-radius layui-btn-primary">
                <i class="layui-icon layui-icon-delete" style="font-size: 14px; color: #FFF;"></i>
                <span>删除</span>
            </button>
        </div>
    </div>
</div>
<script>
    var tableArray = [];
    layui.use(['form', 'table', 'api', 'utill', 'laydate', 'jquery'], function () { //此段代码必不可少
        var table = layui.table,
            setter = layui.setter,
            laytpl = layui.laytpl,
            api = layui.api,
            utill = layui.utill,
            form = layui.form,
            admin = layui.admin,
            view = layui.view,
            element = layui.element,
            form = layui.form,
            $ = layui.jquery,
            laydate = layui.laydate;
        var url = window.location.href;
        var lay = url.slice(url.lastIndexOf('#/')).split('#/')[1];
        sessionStorage.setItem('lay-this', JSON.stringify(lay));
        // 日历控件 
        laydate.render({
            elem: '#time' //指定元素
        })
        // 调坑了
        table.on('tool(maintainWork)', function (obj) { //tcReqId
            if (obj.data.fil05 == 2 || obj.data.fil05 == 1 || obj.data.fil05 == 7) {
                $(this).attr("lay-href", `maintain/popup/create_work#?id=${obj.data.tcReqId}`);
            } else if (obj.data.fil05 == 9 || obj.data.fil05 == 8) {
                $(this).attr("lay-href", `maintain/popup/keep#?id=${obj.data.tcReqId}`);
            }
        });


        // 创建工单 
        $('.btn3').on('click', function () {
            $(this).attr('lay-href', 'maintain/popup/update_work');
        })
        // 转单
        $(".btn2").click(function () {
            tableArray = table.checkStatus("#maintainWork").data;
            if (tableArray.length == 0) return layer.msg("请选择一条数据");
            if (tableArray.length > 1) return layer.msg("只能操作一条数据");
            admin.popup({
                title: '转单',
                area: ['394px', '340px'],
                id: 'changeorder',
                success: function (layero, index) {
                    view(this.id).render('patrol/popup/changeOrder1')
                        .done(function () {
                            $('.inner').eq(0).val(tableArray[0].gen02)
                            $('.inner').eq(1).val(tableArray[0].fil13)
                            form.on('submit(LAY-submit-qd)', function (data) {
                                          let params = {
                                             filuser: $('#gen02').val(),
                                             id: tableArray[0].tcReqId,
                                             fil13: data.field.fil13
                                              }
                                    admin.req({
                                        url: api.host + '/order/giveOrder1.json',
                                        type: "post",
                                        data: JSON.stringify(params),
                                        dataType: 'json',
                                        contentType: 'application/json',
                                        done: function (res) {
                                            if(res.code=='0'){
                                                layer.open({
                                                    content:res.message
                                                });
                                                layui.table.reload('#maintainWork');
                                                layer.close(layer.index);
                                            }else{
                                                layer.open({
                                                    content:res.message
                                                });
                                            }
                                            
                                    }
                               });
                            })
                        });
                }
            });
        });
        // 保养工单  

        // 待执行和已完成
        var _TPL = {
            fil05: function (d) {
                if (d.fil05 == 1) {
                    return "<span>未开始</span>";
                } else if (d.fil05 == 2) {
                    return "<span style='color:blue'>待执行</span>";
                } else if (d.fil05 == 7) {
                    return "<span style='color:red'>超时</span>";
                } else if (d.fil05 == 8) {
                    return "<span style='color:orange'>超时完成</span>";
                }
                else if (d.fil05 == 9) {
                    return "<span style='color:green'>已完成</span>";
                }
            },
            tcPlanFrequency: function (d) {
                if (d.tcPlanFrequency == 'H') {
                    return '<span>每小时</span>';
                } else if (d.tcPlanFrequency == 'D') {
                    return '<span>每日</span>';
                } else if (d.tcPlanFrequency == 'W') {
                    return '<span>每周</span>';
                } else if (d.tcPlanFrequency == 'M') {
                    return '<span>每月</span>';
                } else {
                    return ''
                }
            },
            tcPlanFrequency(d){
                if(d.tcPlanFrequency == 'D'){
                return '<div>日检</div>'
                }else if(d.tcPlanFrequency == 'W'){
                return '<div>周检</div>'
                }else if(d.tcPlanFrequency == 'M'){
                return '<div>月检</div>'
                }else{
                return '<div>小时</div>'
                }
            }
        };
        // 列定制
        utill.columnCustom('#maintainWork', "FilFileBYVO", {
            url: api.host + "/order/selectMaintainList.json",
            templet: _TPL
        });
        utill.showAndHide('.btn2', 'PollingOrderController:MgiveOrder');
       utill.showAndHide('.btn3', 'PollingOrderController:insertMaintain');
       utill.showAndHide('.btn1', 'PollingOrderController:submitBY');

        // 高查弹窗关闭
        $(".close").on("click", function () {
            $(".boxQuery").css("display", "none");
        });

        // 高查清空
        $(".reset").on("click", function () {
            $(this)
                .parent()
                .prev()
                .find("input")
                .val("")
                .parents("ul")
                .find("select")
                .val("");
        });

        // 高查清空
        $(".reset").on("click", function () {
            $(this)
                .parent()
                .prev()
                .find("input")
                .val("")
                .parents("ul")
                .find("select")
                .val("");
        });
        // 高查查询
        $(".sure").on("click", function () {
            let params = {};
            let azp02 = $(".boxQuery")
                .find("input")
                .eq(0)
                .val(); // 公司
            let tc_req_name = $(".boxQuery")
                .find("input")
                .eq(1)
                .val(); // 工单名称
            let fil01 = $(".boxQuery")
                .find("input")
                .eq(2)
                .val(); // 工单编号
            let tc_plan_frequency = $(".boxQuery")
                .find("select")
                .val(); // 巡检计划
            let gen02 = $(".boxQuery")
                .find("input")
                .eq(3)
                .val(); // 巡检人
            let fil12 = $(".boxQuery")
                .find("input")
                .eq(4)
                .val(); // 巡检时间
            let fil07 = $(".boxQuery")
                .find("input")
                .eq(5)
                .val(); // 位置范围
            let tc_detail_fia01a = $(".boxQuery")
                .find("input")
                .eq(6)
                .val(); // 设备编号
            let fil05 = $(".boxQuery")
                .find(".fil05")
                .val(); // 工单状态

            if (azp02) params["azp02"] = azp02;
            if (tc_req_name) params["tc_req_name"] = tc_req_name;
            if (fil01) params["fil01"] = fil01;
            if (tc_plan_frequency) params["tc_plan_frequency"] = tc_plan_frequency;
            if (gen02) params["gen02"] = gen02;
            if (fil12) params["fil12"] = fil12;
            if (fil07) params["fil07"] = fil07;
            if (tc_detail_fia01a) params["tc_detail_fia01a"] = tc_detail_fia01a;
            if (fil05) params["fil05"] = fil05;
            utill.columnCustom('#maintainWork', "FilFileXJAndBYVO", {
                url: api.host + "/order/selectMaintainList.json",
                where: {
                    azp02: azp02,
                    tc_req_name: tc_req_name,
                    fil01: fil01,
                    tc_plan_frequency: tc_plan_frequency,
                    gen02: gen02,
                    fil12: fil12,
                    fil07: fil07,
                    tc_detail_fia01: tc_detail_fia01a,
                    fil05: fil05
                },
                templet: _TPL
            });
            reload(maintainWork, params);
            $(".boxQuery").css("display", "none");

        });
        //是否隐藏转单按钮
        utill.showAndHide('btn2', 'PollingOrderController:MgiveOrder');

        // 高查
        $(".search").on("click", function () {
            $(".boxQuery").css("display", "block");
        });
        table.on("checkbox(maintainWork)", function (obj) {
            tableArray = table.checkStatus("#inspectionSheet").data; // 获取勾选数据
            api1 = api;
        });


        // 批量删除
        $(".btn1").click(function () {
            var arrs_llps2 = [];
            var checkStatus = table.checkStatus('#maintainWork');
            if (checkStatus.data.length == 0) {
                layer.msg('请至少选择一条要删除的数据', { icon: 2 });
                return;
            }
            for (var i = 0; i < checkStatus.data.length; i++) {
                arrs_llps2.push(checkStatus.data[i].tcReqId);
            }
            var obj = {
                "tcReqId": arrs_llps2
            }
            // // 请求
            layer.confirm('真的删除吗？', function (index) {
            admin.req({
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                url: api.host + api.delFilFilexj_llp,
                data: JSON.stringify(obj),
                success: function (data) {
                    layer.msg(data.message);
                    layui.table.reload('#maintainWork'); //重载表格  
                }
            });
        });
        })

        $('.search-blank-inner').focus(function () {
            $('.searchInput').css('width', '100px')
        });
        $('.search-blank-inner').blur(function () {
            $('.searchInput').css('width', '65px')
        });
        form.on('submit(query)', function (data) {
            utill.columnCustom('#maintainWork', "FilFileBYVO", {
                url: api.host + "/order/selectMaintainList.json",
                where: data.field,
            });
            return false;
        });

    });
</script>
<style>
    .box-box {
        position: relative;
    }

    .box .layui-form {
        position: relative;
    }

    .box .layui-table-tool-self {
        top: 5px;
    }

    .box .layui-table-tool {
        position: static;
        min-height: 0;
        padding: 0;
        line-height: 0;
        position: absolute;
    }

    .boxQuery {
        display: none;
        z-index: 999;
        top: 0;
        position: absolute;
        width: 100%;
        background-color: #ffffff;
        margin: 0 auto;
        text-align: left;
        overflow: hidden;
    }

    .boxQuery li {
        padding: 19px 17px 16px;
        font-size: 11px;
        color: #616161;
        float: left;
        text-align: center;
    }

    .boxQuery div {
        margin-bottom: 10px;
        margin-top: 5px;
    }

    .sure {
        width: 70px;
        height: 25px;
        font-size: 11px;
        border-radius: 15px;
        background-color: #FF4C4C;
    }

    .close {
        width: 70px;
        height: 25px;
        border-radius: 15px;
        background-color: #3D8CC9;
    }

    .reset {
        width: 70px;
        height: 25px;
        border-radius: 15px;
        background-color: #FF9F0C;
    }

    .btn1 {
        background: red;
    }
</style>